--
-- Author: ping.wang
-- Date: 2019-07-04 11:53:33
--
-- HandbookTipsPanel
--

local ClassRef = app.mvc.createPanelClass(...)
local panel_2_originWidth = 0 -- panel2原始宽
local panel_2_originHeight = 0 -- panel2原始高
local panel_3_originWidth = 0 -- panel3原始宽
local panel_3_originHeight = 0 -- panel3原始高
local offsetHeight = 10 -- 距离上边距高

local originHeight = 0 -- 文本原始高
local panel_originWidth
local panel_originHeight

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.HandbookChallengeTips))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)
    self._text1 = self._ui.Panel_2:findChild("text_1")
    self._text2 = self._ui.Panel_3:findChild("text_1")
    panel_2_originWidth, panel_2_originHeight = self._ui.Panel_2:getContentSize2()
    panel_3_originWidth, panel_3_originHeight = self._ui.Panel_3:getContentSize2()

    panel_originWidth,panel_originHeight = self._ui.Panel:getContentSize2()
    self:setContentSize( self._ui.Panel:getContentSize() )
end

function ClassRef:onOperate(cb)
    self._onOperate = cb
end

function ClassRef:setContentText(name,str1,str2)
    self._ui.name:setString(name)

    self._text1:setString( str1 )
    self._text1:getVirtualRenderer():setDimensions( 290, 0 )
    local size = self._text1:getVirtualRendererSize()
    self._text1:setContentSize(290,size.height)
    self._ui.Panel_2:setContentSize( cc.size( panel_2_originWidth, size.height +  offsetHeight) )

    self._text2:setString( str2 )
    self._text2:getVirtualRenderer():setDimensions( 290, 0 )
    local size2 = self._text2:getVirtualRendererSize()
    self._text2:setContentSize(290,size2.height)
    self._ui.Panel_3:setContentSize( cc.size( panel_3_originWidth, size2.height +  offsetHeight) )

    self._ui.Panel_3:setPositionY(size2.height + offsetHeight * 1.5)

    local finalSize =  cc.size( panel_originWidth, panel_originHeight - panel_2_originHeight- panel_3_originHeight + size.height + size2.height +  offsetHeight * 3  )

    self._ui.Panel:setContentSize(finalSize)

    self._ui.bg:setContentSize(finalSize)
    self:setContentSize(finalSize)
    ccui.Helper:doLayout(self)
end


return ClassRef
